package com.ag.zlw.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbUserState;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;
import com.ag.zlw.service.UserStateService;

/**
 * 用户状态
 * 
 * @author 钟龙伟
 * 
 */

@Scope("prototype")
@Controller("UserStateAction")
public class UserStateAction extends BaseAction {
	private static final long serialVersionUID = -1478025497648926124L;
	@Resource(name = "UserStateService")
	private UserStateService service;
	private List<TbUserState> UserStateList;
	private String message;
	private String usId;
	private String usName;

	TbUserState tbUserState = new TbUserState();

	public String find() {
		try {
			UserStateList = service.findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "main";
	}

	public String delete() {
		tbUserState.setUsId(usId);
		try {
			service.delete(tbUserState);
			this.setMessage("delete success!");
		} catch (Exception e) {
			this.setMessage("delete fail!");
		}
		return "delete_success";
	}

	public String add() {
		tbUserState.setUsName(usName);
		tbUserState.setA(IDUtil.PRESERVE);
		try {
			service.save(tbUserState);
			this.setMessage("save success!");
		} catch (Exception e) {
			this.setMessage("save fail!");
		}
		return "add_success";
	}

	public String modify() {
		tbUserState.setUsId(usId);
		tbUserState.setUsName(usName);
		tbUserState.setA(IDUtil.PRESERVE);
		try {
			service.modify(tbUserState);
			this.setMessage("modify success!");
		} catch (Exception e) {
			this.setMessage("modify fail!");
		}
		return "modify_success";
	}

	public List<TbUserState> getUserStateList() {
		return UserStateList;
	}

	public void setUserStateList(List<TbUserState> userStateList) {
		this.UserStateList = userStateList;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getUsId() {
		return usId;
	}

	public void setUsId(String usId) {
		this.usId = usId;
	}

	public String getUsName() {
		return usName;
	}

	public void setUsName(String usName) {
		this.usName = usName;
	}

}
